#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
#define OPENTIME 28800
#define CLOSETIME 75600
class PP{
public:
    int arriveTime;
    int playTime;
    int isVIP;
    int serveTime;
    bool isAdded;
    PP(int arriveTime, int playTime, int isVIP){
        this->arriveTime=arriveTime;
        this->playTime=playTime;
        this->isVIP=isVIP;
        this->serveTime=arriveTime;
        this->isAdded=false;
    }
    bool operator < (const PP &pp) const{
        return arriveTime<pp.arriveTime;
    }
};
bool tcmp(const pair<int,int>& a, const pair<int,int>& b){
    return a.second<b.second;
}
bool finalcmp(const PP& a, const PP& b){
    return a.serveTime<b.serveTime;
}
int main(){
    int N;
    cin>>N;
    int i=0;
    vector<PP> pps;
    while(i<N){
        string s;
        int playTime;
        int isVIP;
        cin>>s>>playTime>>isVIP;
        int arriveTime = ((s[0]-'0')*10+(s[1]-'0'))*3600
            +((s[3]-'0')*10+(s[4]-'0'))*60
            +((s[6]-'0')*10+(s[7]-'0'));
        if(playTime>120)
            playTime=120;
        if(arriveTime<CLOSETIME){
            PP pp(arriveTime, playTime*60, isVIP);
            pps.push_back(pp);
        }
        i++;
    }
    int K,M;
    cin>>K>>M;
    int isviptables[101]={0};
    int tables[101]={0};
    int serveNums[101]={0};
    for(i=1;i<=K;i++)
        tables[i]=OPENTIME;
    i=0;
    while(i<M){
        int viptablenum;
        cin>>viptablenum;
        isviptables[viptablenum]=1;
        i++;
    }

    sort(pps.begin(),pps.end());
    //for(i=0;i<pps.size();i++){
    //   cout<<pps[i].arriveTime<<" "<<pps[i].playTime<<" "<<pps[i].isVIP<<endl;
    //}
    for(i=0;i<pps.size();i++){
        //for(int j=1;j<=K;j++){
        //    cout<<tables[j]<<" ";
        //}
        //cout<<endl;
        PP &pp=pps[i];
        if(pp.isAdded)
            continue;

        int firstFreeOrdinaryTableIndex=-1;
        int firstFreeVIPTableIndex=-1;
        int minTableIndex=-1;
        int minTablesTime=0x7fffffff;
        for(int j=1;j<=K;j++){
            if(tables[j]<=pp.arriveTime){
                if(isviptables[j]==1&&firstFreeVIPTableIndex<0)
                    firstFreeVIPTableIndex=j;
                if(isviptables[j]==0&&firstFreeOrdinaryTableIndex<0)
                    firstFreeOrdinaryTableIndex=j;
            }
            if(tables[j]<minTablesTime){
                minTablesTime=tables[j];
                minTableIndex=j;
            }
        }

        if(pp.isVIP==1){// VIP player
            if(firstFreeVIPTableIndex>0){
                serveNums[firstFreeVIPTableIndex]++;
                tables[firstFreeVIPTableIndex]=pp.arriveTime+pp.playTime;
            }else if(firstFreeOrdinaryTableIndex>0){
                serveNums[firstFreeOrdinaryTableIndex]++;
                tables[firstFreeOrdinaryTableIndex]=pp.arriveTime+pp.playTime;
            }else{
                if(minTablesTime<CLOSETIME)
                    serveNums[minTableIndex]++;
                pp.serveTime=minTablesTime;
                tables[minTableIndex]+=pp.playTime;
            }
            pp.isAdded=true;
        }else if(pp.isVIP==0){// not VIP players
            if(firstFreeOrdinaryTableIndex>0&&firstFreeVIPTableIndex>0){
                int ttt=firstFreeOrdinaryTableIndex<firstFreeVIPTableIndex?firstFreeOrdinaryTableIndex:firstFreeVIPTableIndex;
                serveNums[ttt]++;
                tables[ttt]=pp.arriveTime+pp.playTime;
                pp.isAdded=true;
            }else if(firstFreeOrdinaryTableIndex>0){
                serveNums[firstFreeOrdinaryTableIndex]++;
                tables[firstFreeOrdinaryTableIndex]=pp.arriveTime+pp.playTime;
                pp.isAdded=true;
            }else if(firstFreeVIPTableIndex>0){
                serveNums[firstFreeVIPTableIndex]++;
                tables[firstFreeVIPTableIndex]=pp.arriveTime+pp.playTime;
                pp.isAdded=true;
            }else if(isviptables[minTableIndex]==0){
                if(minTablesTime<CLOSETIME)
                    serveNums[minTableIndex]++;
                pp.serveTime=minTablesTime;
                tables[minTableIndex]+=pp.playTime;
                pp.isAdded=true;
            }else if(isviptables[minTableIndex]==1){
                //earliest available table is VIP tables
                //so ordinary player has to let VIP players play first if VIP players are waiting
                int j=i+1;
                bool flag=false;
                for(;pps[j].arriveTime<=minTablesTime&&j<pps.size();j++){
                    if(pps[j].isVIP==1){
                        flag=true;
                        break;
                    }
                }
                if(flag){
                    PP tmp = pps[j];
                    pps.erase(pps.begin()+j);
                    pps.insert(pps.begin()+i, tmp);
                }
                if(minTablesTime<CLOSETIME)
                    serveNums[minTableIndex]++;
                pps[i].serveTime=minTablesTime;
                tables[minTableIndex]+=pps[i].playTime;
                pps[i].isAdded=true;
            }
        }
    }

    //for(int j=1;j<=K;j++){
    //    cout<<tables[j]<<" ";
    //}
    //cout<<endl;
    sort(pps.begin(),pps.end(),finalcmp);
    for(i=0;i<pps.size();i++){
        int arrTime=pps[i].arriveTime;
        int serTime=pps[i].serveTime;
        int waiTime=serTime-arrTime;
        if(serTime>=CLOSETIME){
            continue;
        }
        cout<<setw(2)<<setfill('0')<<(arrTime/3600)<<":";
        cout<<setw(2)<<setfill('0')<<(arrTime%3600/60)<<":";
        cout<<setw(2)<<setfill('0')<<(arrTime%3600%60)<<" ";
        cout<<setw(2)<<setfill('0')<<(serTime/3600)<<":";
        cout<<setw(2)<<setfill('0')<<(serTime%3600/60)<<":";
        cout<<setw(2)<<setfill('0')<<(serTime%3600%60)<<" ";
        cout<<(waiTime+30)/60<<endl;
    }
    cout<<serveNums[1];
    for(i=2;i<=K;i++){
        cout<<" "<<serveNums[i];
    }

    return 0;
}
